/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-03-17 09:11:31
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-18 11:28:20
 */
import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaLocaleProvider } from 'ecCom';
import { WeaTableNew } from 'comsMobx';
import { Modal } from 'antd';

const getLabel = WeaLocaleProvider.getLabel;
const WeaTable = WeaTableNew.WeaTable;

@inject('customReportStore')
@observer
class CustomReport extends React.Component {
  constructor(props) {
    super(props);
    const { getTableData } = this.props.customReportStore;
    getTableData();
  }

  showWarn = (msg) => {
    Modal.warning({
      title: getLabel('517309', '预览失效'),
      content: msg,
    });
  };

  // 重定列
  getColumns = columns => columns.map((col) => {
    switch (col.dataIndex) {
      case 'reportname':
        col.render = (text, record) => {
          let msg = '';
          (!record.url.includes(window.location.origin) || !record.url.includes('/spa/odoc/static4engine/engine.html#/odocengine/previewReport?'))
            && (msg = getLabel('517310', '该报表无法预览，请联系相关人员进行设置'));
          let attribute = { title: text };
          msg && (attribute = { ...attribute, onClick: () => { this.showWarn(msg); } });
          !msg && (attribute = { ...attribute, href: record.url, target: '_blank' });
          return <a {...attribute}>{text}</a>;
        };
        break;
    }
    return col;
  });


  render() {
    const { customTableStore } = this.props.customReportStore;

    return (
      <div>
        <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@i7x2z8`}
          comsWeaTableStore={customTableStore}
          hasOrder={true}
          getColumns={this.getColumns}
        />
      </div>
    );
  }
}


export default CustomReport;
